clear all; close all; clc
 addpath('../LibForSerial/LibrarySLP','../LibForSerial/LibraryLeSage/','../LibForSerial/LibVAR');

%----------- Load shocks using two identification schemes ----------------%
LogLevel = 1; 
  NumberConsecutiveshocks = 2; % 1 previous shocks that is  positive, and the 2nd one is positive too 

  shockchoice = 1; % 1 means BdBG ReStud shock (from VAR system with IP)
 %shockchoice = 2; % 2 means BdBG ReStud shock (from Predictive regressions)
cd ../Figure2_4_MKTVol/DataShocks/
    LoadShocksMandQpositiveRVsp500FromVAR;sample=[ 1983 6; 2019  12];
  load uRV_from_PredReg
fprintf('Correlation between uRV from predictive vs VAR is %3.3f \n', corr(uRV_from_PredReg(end-size(uRV,1)+1:end),uRV)); 
cd ../../Figure1_MKTVol

ushock = uRV;
%-------------------------------------------------------------------------%
%% Figure 1 - Panel (c) and (d)
[Years,M] = meshgrid(1983:2019, 1:1:12);
calM = datenum([Years(:), M(:), 28*ones(numel(Years),1)]); % The Serial Dates

ticks = datenum([(1983:6:2019)',12*ones(7,1), 28*ones(7,1) ]);
lim_x =[datenum(  1983,06,1), datenum(2019,12,31)];

LineWidth =  4.0;   
%-------------------------------------------------------------------------%
figure(1)
subplot(2,1,1)
       line(calM(6:end),   ls_RV, 'linewidth',LineWidth);      title(['log MKT volatility'])
  set(gca, 'XLim' , lim_x)
% set(gca, 'YLim' , [-.1 5]); %ONLY FOR FIGURES 23 & 24
set(gca, 'XTick', ticks)
datetick('keepticks','keeplimits')
box on
recessionplot
set(gca,'FontSize',32)

subplot(2,1,2)
h_1 = line(calM(6:end),     ushock, 'linewidth',LineWidth);      title(['Time Series of MKT volatility shocks'])
hold on
      line(calM(6:end) , 2*ones(size(calM(6:end),1),1),'color','k','linewidth',LineWidth);
      line(calM(6:end) ,-2*ones(size(calM(6:end),1),1),'color','k','linewidth',LineWidth);     
h_0  =line(calM(6:end) , 0*ones(size(calM(6:end),1),1),'color','r','linewidth',LineWidth/2);
uistack(h_0, 'top')


  set(gca, 'XLim' , lim_x)
set(gca, 'XTick', ticks)
datetick('keepticks','keeplimits')
box on
recessionplot
set(gca,'FontSize',32)